<template>
    <view class="store-dashboard">
        <!-- 线上展厅 -->
        <view v-if="showEmpty">
            <view v-for="(item,index) in productsList" :key="index" class="store-dashboard-item">
                <view class="chart-section">
                    <view v-for="(itemsrc,srcIndex) in item.imagesList" :key="srcIndex" class="chart-item">
                        <image class="chart-item-img" :src="itemsrc" mode="widthFix"></image>
                    </view>
                </view>
                <view class="product-list">
                    <view class="product-item" v-for="(product,nindex) in item.products" :key="product.id">
                        <image class="product-image" :src="product.imagelist[0]" mode="aspectFill" />
                        <view class="product-info">
                            <view class="product-name">{{ product.name }}</view>
                            <view class="product-desc">{{ product.remark }}</view>
                            <view class="product-footer">
                                <text class="price">¥{{ product.price }}</text>
                                <view class="view-btn" @click="viewProduct(product)">去查看</view>
                            </view>
                        </view>
                    </view>
                </view>
            </view>
        </view>
        <view v-else class="flex justify-center items-center bg-white">
          <Empty :emptyInfo="emptyInfo" />
        </view>
    </view>
</template>

<script setup>
import { ref } from 'vue'
import { shopApi } from "@/api";
import { IMG_URL2 } from "@/config";
import Empty from "@/components/empty.vue";

let showEmpty=ref(true)
const EmptyImage = ref(IMG_URL2 + "empty/normal.png");
const emptyInfo = ref({
  image: EmptyImage,
  width: 300,
  height: 300,
  tip: "暂无数据~"
});
let productsList=ref([])
const getData = () => {
  shopApi.EXHIBITIONHALLGETPANORAMAEXHIBITIONHALLLIST().then((res) => {
    if (res && res.code == 200) {
        productsList.value=res.result&&res.result.length>0?res.result.map(item=>{
            return {
                ...item,
                imagesList: item.images?item.images.split(','):[],
                products:item.products.map(product=>{
                    return {
                        ...product,
                        imagelist:product.images?product.images.split(','):[]
                    }
                })
            }
        }
        ):[]
        if(productsList.value.length==0){
            showEmpty.value=true
        }
    } else {
      uni.showToast({
        title: res.errMsg,
        icon: "success"
      });
    }
  });
};
const viewProduct = (product) => {
    uni.navigateTo({
        url: `/pages/good/details?id=${product.productId}`
    })
}
onShow(async () => {
    getData()
})
</script>

<style lang="scss" scoped>
.store-dashboard {
    min-height: 100vh;
    background-color: #f5f5f5;
    padding-bottom: 40rpx;
    .chart-section {
        padding: 0 24rpx;
        box-sizing: border-box;
        margin-bottom: 20rpx;
        
        .chart-item{
            width: 100%;
            margin-bottom: 20rpx;
            border-radius: 12rpx;
            overflow: hidden;
            .chart-item-img{
                width: 100%;
                border-radius: 12rpx;
            }
            &:last-child{
                margin-bottom: 0;
            }
        }
    }

    .product-list {
        padding: 0 24rpx;
        box-sizing: border-box;
        .product-item {
            display: flex;
            background-color: #fff;
            padding: 20rpx;
            box-sizing: border-box;
            margin-bottom: 20rpx;
            border-radius: 12rpx;

            .product-image {
                width: 160rpx;
                height: 160rpx;
                border-radius: 8rpx;
                margin-right: 20rpx;
                background-color: #f5f5f5;
            }

            .product-info {
                flex: 1;
                display: flex;
                justify-content: space-between;
                flex-wrap: wrap;
                .product-name {
                    width: 100%;
                    font-size: 28rpx;
                    color: #333;
                    font-weight: bold;
                    margin-bottom: 10rpx;
                }

                .product-desc {
                    width: 100%;
                    font-size: 24rpx;
                    color: #666;
                    margin-bottom: 20rpx;
                }

                .product-footer {
                    display: flex;
                    justify-content: space-between;
                    align-items: center;
                    width: 100%;
                    .price {
                        font-size: 32rpx;
                        color: #333;
                        font-weight: bold;
                    }

                    .view-btn {
                        background-color: #fff;
                        color: rgba(227, 115, 24, 1);
                        font-size: 24rpx;
                        padding: 4rpx 18rpx;
                        box-sizing: border-box;
                        border-radius: 10rpx;
                        border: 1rpx solid rgba(227, 115, 24, 1);

                        &:active {
                            opacity: 0.9;
                        }
                    }
                }
            }
        }
    }
}
</style>